#ifndef ADDFRIENDSWIDGET_H
#define ADDFRIENDSWIDGET_H

#include <QWidget>
#include <QString>
#include <QJsonObject>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>

#include "server.h"
#include "message.h"

namespace Ui {
class AddFriendsWidget;
}

class AddFriendsWidget : public QWidget
{
    Q_OBJECT

public:
    explicit AddFriendsWidget(QWidget *parent = nullptr);
    ~AddFriendsWidget();

    QString userId() const;
    void setUserId(const QString &newUserId);

signals:
    void signal_friendRequest(Message);

    void signal_addFriendSuccess(QJsonObject jsonObj);

public slots:
    void slot_receiveFriendRequest(Message);

private slots:
    void on_pushButton_search_clicked();

    void slot_finishRequest(QNetworkReply *);

    void slot_friendRequest(Message);

    void slot_agreeFriendRequest(QString fromId);

    void slot_agreeFriendRequestReply(QNetworkReply *);

private:
    Ui::AddFriendsWidget *ui;

    QNetworkRequest m_request;
    QNetworkAccessManager m_manager;
    QString m_addFriendUrl = "http://" + Server::serverAddr() + ":" + Server::port() + "/friends";

    QString m_userId;

    void addFriendItem(QString username, QString userId);
    void addFriendNotificationItem(Message);
};

#endif // ADDFRIENDSWIDGET_H
